<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "com.alipay.api.*" %>
<%@ page import = "com.zhengke.pojo.*" %>
<%@ page import = "com.alipay.api.request.AlipayTradePagePayRequest" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'memberAlipay.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
  </head>
  <body>
   		<%
		//根据提交的商品查询基本信息
		String memberId = request.getParameter("member_id");//会员的id
		String member_money = request.getParameter("member_money");//会员充值的金额
		String memberName = request.getParameter("member_name");//会员的姓名
		//订单号
		SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss");
		String orderSn = simpledateformat.format(Calendar.getInstance().getTime());

		//向支付宝发起请求
		//获得初始化的AlipayClient
		AlipayClient alipayClient = new DefaultAlipayClient(AlipayEntity.gatewayUrl, AlipayEntity.app_id,
				AlipayEntity.merchant_private_key, "json", AlipayEntity.charset, AlipayEntity.alipay_public_key,
				AlipayEntity.sign_type);

		//设置请求参数
		AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
		alipayRequest.setReturnUrl(AlipayEntity.return_url);
		alipayRequest.setNotifyUrl(AlipayEntity.notify_url);
		/**
		 * 设置订单支付时候的信息
		 */
		String out_trade_no = orderSn;//订单的名称
		String total_amount = member_money;//订单的金额
		String subject = "会员充值订单";//订单的名称
		String body = "***id为："+memberId+"，充值金额为"+member_money+"的订单***";//订单的描述
		
		alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\"," + "\"total_amount\":\""
				+ total_amount + "\"," + "\"subject\":\"" + subject + "\"," + "\"body\":\"" + body + "\","
				+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");

		//请求
		String result = "";
		try {
			result = alipayClient.pageExecute(alipayRequest).getBody();
		} catch (AlipayApiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//输出
		out.println(result);
	%>
  </body>
</html>
